package com.scau402.system1.mapper;

import com.scau402.system1.domain.po.WmsOutboundOrderDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.scau402.system1.domain.query.WmsOutboundOrderQuery;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品出库单主表 Mapper 接口
 * </p>
 *
 * @author
 * @since 2023-12-23
 */
@Mapper
public interface IWmsOutboundOrderMapper extends BaseMapper<WmsOutboundOrderDO> {

    String getMaxCode(Map<String, Object> params);

	int checkOrderCodeExist(String currentOrderCode);

	WmsOutboundOrderDO selectWmsOutboundOrderByOrderCode(String outboundOrderCode);

    List<WmsOutboundOrderDO> selectWmsOutboundOrderList(WmsOutboundOrderQuery query);

    @Select("" +
            "        select settlement_cycle, lend_days, client_id, client_name,\n" +
            "        id, order_type, order_code, order_batch, order_date, valid_date, supplier_id, warehouse_id, des_warehouse_id, processor_id, settlement_type, settlement_ratio, is_settle, settle_time, settle_by, create_by, create_time, update_by, update_time, status, del_flag, remark, tenant_id, dept_id " +
            "        from wms_new_outbound_order\n" +
            "        wo\n" +
            "        LEFT JOIN (SELECT id as cid, client_name from wms_basic_client WHERE del_flag = '0') AS wc ON (wc.cid = wo.client_id)\n" +
            "        where \n" +
            "            del_flag = '0' and\n" +
            "            order_code = #{ordercode} \n"+
            "        ORDER BY create_time DESC\n" +
            "")
    WmsOutboundOrderDO selectOutboundOrderListByOrderCodes(String orderCode);

    @Select("select order_type from wms_new_outbound_order where id=#{outboundOrderCode}")
    String getOutboundType(String outboundOrderCode);
}
